package com.medical_houduan.service.Impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.medical_houduan.commons.Result;
import com.medical_houduan.dto.DrugDto;
import com.medical_houduan.mapper.DrugMapper;
import com.medical_houduan.pojo.Drug;
import com.medical_houduan.service.DrugService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service

public class DrugServiceImpl implements DrugService {

    @Autowired
    DrugMapper drugMapper;
    //添加药品
    @Override
    public Result addDrugService(DrugDto drugDto) {

        if(drugDto==null){
            return new Result(201,"添加时填写完整的信息");
        }
        if("".equals(drugDto.getDrugName())||drugDto.getDrugName()==null){
            return new Result(202,"添加时，药品名称信息必填");
        }

        if("".equals(drugDto.getDrugInfo())||drugDto.getDrugInfo()==null){
            return new Result(203,"添加时，药品信息必填");
        }

        if("".equals(drugDto.getDrugEffect())||drugDto.getDrugEffect()==null){
            return new Result(204,"添加时，药品效果必填");
        }

        if("".equals(drugDto.getDrugImg())||drugDto.getDrugImg()==null){
            return new Result(205,"添加时，药品图片必须上传");
        }

        if("".equals(drugDto.getPublisher())||drugDto.getPublisher()==null){
            return new Result(206,"添加时，药品发布者必填");
        }

        Drug drug = new Drug();
        BeanUtils.copyProperties(drugDto,drug);
        drug.setCreateTime(new Date());
        drug.setUpdateTime(new Date());

        int row = drugMapper.insert(drug);
        if(row!=1){
            return new Result(207,"添加药品失败");
        }


        return new Result(200,"添加成功",drug);
    }


    //修改药品信息
    @Override
    public Result updateDrugService(DrugDto drugDto) {
        if(drugDto.getDrugId()==null){
            return new Result(201,"要输入的药品不存在");
        }


        return null;
    }

    //根据id查询药品
    @Override

    public Result selectDrugByID(Long drugId) {
        if(drugId == null){
            return new Result(201, "请输入要查询的药品id");
        }

        // 使用selectById直接根据主键查询
        Drug drug = drugMapper.selectById(drugId);

        if (drug == null){
            return new Result(202, "药品不存在");
        }

        return new Result(200, "查询成功", drug);
    }


    //删除药品信息


    //查询所有药品



}
